#! /usr/bin/env python
#coding=utf-8

import redis
import sys
import os

reload(sys)
sys.setdefaultencoding('utf8')
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from tdm_config import *

g_city = '*'
g_jxd = '*'
g_tdmtype = '*'
g_server = '*'
g_serv_item = '*'

g_dev = '*'
g_net_item = '*'

def redis_clear_item(key):
    def _redis_clear_item(func):
        def __redis_clear_item(city, jxd, dev, item):
            r = redis.Redis(host='127.0.0.1', db=1)
            db_item = '%s_%s_%s_%s_%s'%(key, city, jxd, dev, item)
            print db_item
            item_list = r.keys(db_item)
            for i in item_list:
                print "REMOVE", i
                r.delete(i)
            db_item = '%s:%s_%s_%s:%s'%(key, city, jxd, dev, item)
            print db_item
            item_list = r.keys(db_item)
            for i in item_list:
                print "REMOVE", i
                r.delete(i)
        return __redis_clear_item
    return _redis_clear_item

def redis_clear_warn_alert_log(key):
    def _redis_clear_warn_alert_log(func):
        def __redis_clear_warn_alert_log():
            r = redis.Redis(host='127.0.0.1', db=1)
            warn_list = r.hkeys(key)
            for i in warn_list:
                print "REMOVE", i
                r.hdel(key, i)
        return __redis_clear_warn_alert_log
    return _redis_clear_warn_alert_log


@redis_clear_item(tdm_redis_key_server_item_prefix)
def redis_clear_server_item(city, jxd, server, item):
    pass

@redis_clear_item(tdm_redis_key_network_item_prefix)
def redis_clear_network_item(city, jxd, dev, item):
    pass

@redis_clear_warn_alert_log(tdm_redis_key_server_item_warn)
def redis_clear_server_warn():
    pass

@redis_clear_warn_alert_log(tdm_redis_key_server_item_alert)
def redis_clear_server_alert():
    pass

@redis_clear_warn_alert_log(tdm_redis_key_log)
def redis_clear_log():
    pass

@redis_clear_warn_alert_log(tdm_redis_key_network_item_warn)
def redis_clear_network_warn():
    pass

@redis_clear_warn_alert_log(tdm_redis_key_network_item_alert)
def redis_clear_network_alert():
    pass


if __name__ == '__main__':
    redis_clear_server_item(g_city, g_jxd, g_tdmtype, g_serv_item)
    redis_clear_network_item(g_city, g_jxd, g_dev, g_net_item)
    redis_clear_server_warn()
    redis_clear_server_alert()
    redis_clear_log()
    redis_clear_network_warn()
    redis_clear_network_alert()

